package uk.co.hephistocles.blobGame;

import java.util.List;

import android.app.ListActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.flurry.android.AppCircle;
import com.flurry.android.FlurryAgent;
import com.flurry.android.Offer;

public class AppCircleActivity extends ListActivity {
	String[] names;
	String[] urls;
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		

		
        AppCircle appCircle = FlurryAgent.getAppCircle();
        //appCircle.openCatalog(AppCircleActivity.this, "MainCatalog");
        List<Offer> offers = appCircle.getAllOffers("MainCatalog");

		// Create an array of Strings, that will be put to our ListActivity
		names = new String[offers.size()];
		urls = new String[offers.size()];
        
        for (int i=0; i<offers.size(); i++) {
            System.out.println("Got an offer! " + offers.get(i).getUrl()+ ": " 
            		+ " ( " + offers.get(i).getPrice()+ " )");
        	names[i] = offers.get(i).getName() + "($" + (offers.get(i).getPrice()/100.0) + ")";
        	urls[i] = offers.get(i).getUrl();
        	System.out.println(urls[i]);
        }

		// Create an ArrayAdapter, that will actually make the Strings above
		// appear in the ListView
		this.setListAdapter(new ArrayAdapter<String>(this,
				android.R.layout.simple_list_item_1, names));
	}

	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		super.onListItemClick(l, v, position, id);
		// Get the item that was clicked
		String url = urls[position];
		System.out.println(url);
		Intent i = new Intent(Intent.ACTION_VIEW);
		i.setData(Uri.parse(url));
		startActivity(i);
	}
}
